package com.xoa.service.party;

import com.xoa.dao.party.GridHolidayMapper;
import com.xoa.model.party.GridHoliday;
import com.xoa.util.ToJson;
import com.xoa.util.page.PageParams;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by gsb on 2018/1/16.
 */
@Service
public class GridHolidayService {

    @Resource
    private GridHolidayMapper gridHolidayMapper;

    /**
     *
     * 创建作者:   季佳伟
     * 创建日期:   2018-1-16 上午10:21:51
     * 类介绍  :   添加
     * 构造参数:
     *
     */
    public ToJson<GridHoliday> insert(GridHoliday gridHoliday){
        ToJson<GridHoliday> json = new ToJson<>();
        try {
            int count = gridHolidayMapper.insertSelective(gridHoliday);
            if (count>0){
                json.setFlag(0);
                json.setMsg("ok");
            }
        }catch (Exception e){
            e.printStackTrace();
            json.setFlag(1);
            json.setMsg(e.getMessage());
        }
        return json;
    }

    /**
     *
     * 创建作者:   季佳伟
     * 创建日期:   2018-1-16 上午10:21:51
     * 类介绍  :   修改
     * 构造参数:
     *
     */
    public ToJson<GridHoliday> update(GridHoliday gridHoliday){
        ToJson<GridHoliday> json = new ToJson<>();
        try {
          int count = gridHolidayMapper.updateByPrimaryKeySelective(gridHoliday);
          if (count>0){
              json.setFlag(0);
              json.setMsg("ok");
          }
        }catch (Exception e){
            e.printStackTrace();
            json.setFlag(1);
            json.setMsg(e.getMessage());
        }
        return json;
    }

    /**
     *
     * 创建作者:   季佳伟
     * 创建日期:   2018-1-16 上午10:21:51
     * 类介绍  :   删除
     * 构造参数:
     *
     */
    public ToJson<GridHoliday> deleteByPrimaryKey(Integer hid){
        ToJson<GridHoliday> json = new ToJson<>();
        try {
            int count = gridHolidayMapper.deleteByPrimaryKey(hid);
            if (count>0){
                json.setFlag(0);
                json.setMsg("ok");
            }
        }catch (Exception e){
            e.printStackTrace();
            json.setFlag(1);
            json.setMsg(e.getMessage());
        }
        return json;
    }

    /**
     *
     * 创建作者:   季佳伟
     * 创建日期:   2018-1-16 上午10:21:51
     * 类介绍  :  详情
     * 构造参数:
     *
     */
    public ToJson<GridHoliday> selectByPrimaryKey(Integer hid){
        ToJson<GridHoliday> json = new ToJson<>();
        try {
            GridHoliday gridHoliday = gridHolidayMapper.selectByPrimaryKey(hid);
            json.setObject(gridHoliday);
            json.setFlag(0);
            json.setMsg("ok");
        }catch (Exception e){
            e.printStackTrace();
            json.setFlag(1);
            json.setMsg(e.getMessage());
        }
        return json;
    }
    /**
     *
     * 创建作者:   季佳伟
     * 创建日期:   2018-1-16 上午10:21:51
     * 类介绍  :  列表
     * 构造参数:
     *
     */
    public ToJson<GridHoliday> selectList(Integer page, Integer pageSize,
                                          boolean useFlag){
        ToJson<GridHoliday> json = new ToJson<>();
        try {
            Map<String, Object> map = new HashMap<String, Object>();
            PageParams pageParams=new PageParams();
            pageParams.setPage(page);
            pageParams.setPageSize(pageSize);
            pageParams.setUseFlag(useFlag);
            map.put("page",pageParams);
            List<GridHoliday> gridHolidayList = gridHolidayMapper.selectHoliday(map);
            json.setObj(gridHolidayList);
            json.setTotleNum(gridHolidayMapper.selectHolidayCount(map));
            json.setMsg("ok");
            json.setFlag(0);
        }catch (Exception e){
            e.printStackTrace();
            json.setFlag(1);
            json.setMsg(e.getMessage());
        }
        return json;
    }
}
